var Ajax = 
{
	Request : function(param,callback,show){
		if(typeof(show)=='undefined') showanimation = true;
		else showanimation = false;
		var requestUrl = '../ajax/ajax.php';
		$.post(requestUrl,param,callback,'json');
	},
	getWinRect : function(){
		var ww, wh; //window
		if(typeof(window.innerWidth) == "number") {
			//FireFox
			ww = window.innerWidth;
			wh = window.innerHeight;
		}
		else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
		{
			ww=document.documentElement.clientWidth;
			wh=document.documentElement.clientHeight;
		}
		else {
			//Unknown
			if(document.body&&(document.body.clientWidth||document.body.clientHeight))
			{
				ww=document.body.clientWidth;
				wh=document.body.clientHeight;
			}
		}
		return {width:ww,height:wh};
	},
	scrollWinRect : function(){
		var yScrolltop;
		var xScrollleft;
		if (self.pageYOffset || self.pageXOffset){
			yScrolltop = self.pageYOffset;
			xScrollleft = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
			yScrolltop = document.documentElement.scrollTop;
			xScrollleft = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			yScrolltop = document.body.scrollTop;
			xScrollleft = document.body.scrollLeft;
		}
		return {left:xScrollleft,top:yScrolltop};
	},
	rectScrollOrResize : function(){
		var node = $(document.body).find('div._ajaxloadingclass');
		var scrollRect = Ajax.scrollWinRect();
		var winRect = Ajax.getWinRect();
		var showLeft = (scrollRect.left + winRect.width - 30) / 2;
		var showTop = (scrollRect.top + winRect.height - 30) / 2;
//		var showLeft = (scrollRect.left + winRect.width - 110);
//		var showTop = (scrollRect.top + 5);
		node.css({position:'absolute',top:showTop + 'px',left:showLeft + 'px'});
		return {x:showLeft,y:showTop};
	},
	recCenter : function(){
		var scrollRect = Ajax.scrollWinRect();
		var winRect = Ajax.getWinRect();
		var showLeft = (scrollRect.left + winRect.width) / 2;
		var showTop = (scrollRect.top + winRect.height) / 2;
		return {x:showLeft,y:showTop};
	}
}

var show = false;
var showanimation = true;
$(function(){
	$.ajaxTimeout(20000);
	LodingNode = $("<div class='_ajaxloadingclass'><img src='../images/ajax-loader.gif' /></div>");
	var rect = Ajax.rectScrollOrResize();
	LodingNode.css({position:'absolute',top:rect.y + 'px',left:rect.x + 'px'});
	LodingNode.appendTo(document.body).hide();	
	$(document.body).ajaxStart(function(){
		if(!show && showanimation){
			$(this).find('div._ajaxloadingclass').fadeIn('slow');
			show = true;
		}
	});
	$(document.body).ajaxSend(function(){
		if(!show && showanimation){
			$(this).find('div._ajaxloadingclass').fadeIn('slow');
			show = true;
		}
	});
	$(document.body).ajaxStop(function(){
		if(show){
			$(this).find('div._ajaxloadingclass').fadeOut('slow');
			show = false;
		}
	});
	$(document.body).ajaxComplete(function(){
		if(show){
			$(this).find('div._ajaxloadingclass').fadeOut('slow');
			show = false;
		}
	});
	$(document.body).ajaxSuccess(function(){
		if(show){
			$(this).find('div._ajaxloadingclass').fadeOut('slow');
			show = false;
		}
	});	
	$(document.body).ajaxError(function(){
		if(show){
			$(this).find('div._ajaxloadingclass').fadeOut('slow');
			show = false;
		}
	});
	$(window).scroll(Ajax.rectScrollOrResize);
	$(window).resize(Ajax.rectScrollOrResize);	
});